import com.alibaba.fastjson.JSON;
import com.beta.auth.constants.BusinessConstants;
import com.beta.auth.utils.JwtUtil;
import com.beta.cat.utils.AESUtil;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author gwqin
 * @description
 * @date 2023-08-23 16:52
 */
public class MakeData {
    public static void main(String[] args) throws IOException {
        /*int managerCount = 5000; // 理财师数量
        int custCountPerManager = 100; // 每个理财师的客户数量

        File dataFile = new File("C:\\Users\\beta\\Desktop\\data.csv");
        if (dataFile.exists()) {
            dataFile.delete();
        }
        dataFile.createNewFile();

        List<String> managerIds = makeManagerId(managerCount);
        int start = 1000000000;
        for (String managerId : managerIds) {
            List<Integer> custIds = makeCustId(custCountPerManager, start);
            List<String> lines = new ArrayList<>(custIds.size());
            String bjwt = getBjwt(managerId);
            String signet = getSignet(managerId);
            for (Integer custId : custIds) {
                String line = managerId + "," + custId + "," + SM4Helper.encryptSm4(String.valueOf(custId)) + "," + bjwt + "," + signet;
                lines.add(line);
            }
            FileUtils.writeLines(dataFile, lines, true);
            start = start + custCountPerManager;
        }*/

        List<String> strings = FileUtils.readLines(new File("C:\\Users\\beta\\Desktop\\ljin-1010.csv"));
        for (String string : strings) {
            String acc = string.split(",")[0];
            String encrypted = SM4Helper.encryptSm4(acc);
            System.out.println(encrypted);
        }
    }

    private static String getSignet(String id) {
        long ct = System.currentTimeMillis();
        Map<String, String> signet = new HashMap<>(2);
        signet.put("userId", id);
        signet.put("ct", String.valueOf(ct));
        return AESUtil.encrypt(JSON.toJSONString(signet), BusinessConstants.AES_KEY);
    }

    private static List<Integer> makeCustId(int number, int start) {
        List<Integer> custIds = new ArrayList<>(number);
        for (int i = 1; i <= number; i++) {
            custIds.add(start + i);
        }

        return custIds;
    }

    private static List<String> makeManagerId(int number) {
        List<String> managerIds = new ArrayList<>(number);
        int start = 100000;
        for (int i = 1; i <= number; i++) {
            managerIds.add("HR_" + (start + i));
        }

        return managerIds;
    }
}
